<template>
  <div class="trend">
    <div class="text" :style="{ color: textColor }">
        <slot v-if='slots.default'></slot>
        <div v-else>{{text}}</div>
  </div>
    <div class="icon">
      <!-- <el-icon-arrowup :style="{color: upIconColor}" v-if="type === 'up'"></el-icon-arrowup>
                 <el-icon-arrowdown  :style="{color: downIconColor}" v-else></el-icon-arrowdown> -->
      <component
        :is="`el-icon-${toLine(upIcon)}`"
        :style="{ color: !reverseColor ? upIconColor : '#52c41a' }"
        v-if="type === 'up'"
      ></component>
      <component
        :is="`el-icon-${toLine(downIcon)}`"
        :style="{ color: !reverseColor ? downIconColor : '#5ff2d' }"
       v-else
      ></component>
    </div>
  </div>
</template>

<script lang='ts' setup >
import { useSlots, computed } from "vue";
import { toLine } from "../../../utils";
let props = defineProps({
  // 标记趋势是上升还是下降
  type: {
    type: String,
    default: "up",
  },
  // 趋势显示的文字
  // 1 父组件传递过来的数据
  // 2 插槽
  text: {
    type: String,
    default: "文字",
  },

  // 上升趋势图标颜色
  upIconColor: {
    type: String,
    default: "#f5222d",
  },
  // 下降趋势图标颜色
  downIconColor: {
    type: String,
    default: "#52c41a",
  },
  reverseColor: {
      type:Boolean,
      default: false
  },
  // 上升趋势的文字颜色
  upTextColor: {
    type: String,
    default: "#f5222d",
  },
  // 下降趋势文字颜色
  downTextColor: {
    type: String,
    default: "#52c41a",
  },
  upIcon: {
    type: String,
    default: "ArrowUp",
  },
  downIcon: {
    type: String,
    default: "ArrowDown",
  }
});

//获取插槽的内容
let slots = useSlots();

// 文字颜色
let textColor = computed(() => {
  return props.type === "up" ? props.upTextColor : props.downTextColor;
});
</script>

<style lang="scss">
.trend {
  display: flex;
  align-items: center;
  .text {
    font-size: 12px;
    margin-right: 4px;
  }
  .icon {
    svg {
      width: 0.8em;
      height: 0.8em;
    }
  }
}
</style>